package com.cloud.code.牛客网;

import java.util.*;

public class Test49 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String line = scanner.nextLine();
            int vlan = Integer.parseInt(scanner.nextLine());

            String[] split = line.split(",");
            Map<Integer, String> map = new TreeMap<>();
            for (int i = 0; i < split.length; i++) {
                if (split[i].contains("-")) {
                    String[] splitGroup = split[i].split("-");
                    map.put(Integer.valueOf(splitGroup[0]), split[i]);
                } else {
                    map.put(Integer.parseInt(split[i]), null);
                }
            }

            Iterator<Map.Entry<Integer, String>> iterator = map.entrySet().iterator();
            while (iterator.hasNext()) {

                Map.Entry<Integer, String> next = iterator.next();
                Integer key = next.getKey();
                if (key > vlan) {
                    break;
                }
                if (key == vlan) {
                    if (map.get(key) == null) {
                        iterator.remove();
                    } else {
                        String[] values = map.get(key).split("-");
                        if (Integer.parseInt(values[1]) - Integer.parseInt(values[0]) >= 1) {
                            map.put(key, Integer.parseInt(values[0]) + 1 + "-" + values[1]);
                        } else {
                            map.put(key, values[1]);
                        }
                    }
                }

                if (key < vlan) {
                    if (map.get(key) != null) {
                        String[] values = map.get(key).split("-");
                        int value0 = Integer.parseInt(values[0]);
                        int value1 = Integer.parseInt(values[1]);
                        if (value1 >= vlan) {
                            int temp = vlan - 1;
                            if (temp == value0) {
                                map.put(key, String.valueOf(key));
                            } else {
                                map.put(key, value0 + "-" + temp);
                            }

                            int tempEnd = vlan + 1;
                            if (tempEnd == value1) {
                                map.put(value1, String.valueOf(value1));
                            }
                            if (tempEnd < value1) {
                                map.put(tempEnd, tempEnd + "-" + value1);
                            }
                        }
                    }
                }

            }

            Iterator<Map.Entry<Integer, String>> iterator1 = map.entrySet().iterator();
            while (iterator1.hasNext()) {
                Map.Entry<Integer, String> next = iterator1.next();
                if (next.getValue() != null) {
                    System.out.print(next.getValue() + ",");
                } else {
                    System.out.print(next.getKey() + ",");
                }
            }

        }
    }
}
